package org.yjhking.feignclient;

import feign.hystrix.FallbackFactory;
import org.springframework.stereotype.Component;
import org.yjhking.dto.Movie;
import org.yjhking.query.AjaxResult;

@Component
public class MovieFeignClientFallbackFactory implements FallbackFactory<MovieFeignClient> {
    
    /**
     * 生产托底类的方法，需要使用匿名内部类的方式，返回要托底接口的实现类，实现类方法就是托底方法
     */
    @Override
    public MovieFeignClient create(Throwable throwable) {
        // 1.打印接口错误，方便查找错误
        throwable.printStackTrace();
        return new MovieFeignClient() {
            @Override
            public AjaxResult getMovieList() {
                return new AjaxResult(false, "熔断");
            }
            
            @Override
            public AjaxResult buy(Movie movie) {
                return new AjaxResult(false, "熔断");
            }
            
            @Override
            public AjaxResult free(Long id) {
                return new AjaxResult(false, "熔断");
            }
            
            @Override
            public AjaxResult watchMovie(Movie movie) {
                return new AjaxResult(false, "熔断");
            }
        };
    }
}